package cn.com.baiwei.service.impl;

import cn.com.baiwei.mapper.EmployeeMapper;
import cn.com.baiwei.pojo.Employee;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Service
public class LoginServiceimpl {

    @Resource
    private EmployeeMapper employeeMapper;
    public Map<String,Object> login(Employee employee , HttpSession session){
        Map<String, Object> map = new HashMap<>();
        map.put("code",601);
        map.put("msg","用户名或密码错误");
        String phone = employee.getEmployeePhone();
        String mima = employee.getEmployeePassword();
        Employee returm_employee = employeeMapper.login(phone);
        System.out.println(returm_employee);

        if(returm_employee != null && returm_employee.getEmployeePassword().equals(mima)){
            map.put("code",200);
            map.put("msg","登录成功");
            map.put("data",returm_employee);
        }
        return map;
    }
//public Map<String, Object> login(Employee employee, HttpSession session){
//        Map<String, Object> map = new HashMap<>();
//    Employee return_employee = employeeMapper.login(employee.getEmployeePhone());
//        if(return_employee == null) {
//            map.put("code", 601);
//            map.put("msg", "用户名或者密码错误!");
//        }
//        else {
//            if(return_employee.getPassword().equals(employee.getPassword())) {
//                map.put("code", 200);
//                map.put("msg", "登录成功!");
//                map.put("data", return_employee);
//                session.setAttribute("employee", return_employee);
//            }
//            else {
//                map.put("code", 601);
//                map.put("msg", "用户名或者密码错误!");
//            }
//        }
//        return map;
//    }
}
